from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST

'''财务页面'''


class TaskPage(BasePage):
    # 添加应收款页面url
    url='http://{}/crm/index.php?m=task'.format(HOST)

    # 定位添加任务按钮
    add_task_btn_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div/a')
    # 定位第一条任务
    first_task_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    # 定位最后一条任务
    last_task_locator= (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(5) > td:nth-child(1) > input')
    # 定位最后一条任务的查看
    look_last_task_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(5) > td:nth-child(10) > a:nth-child(1)')
    # 定位最后一条任务的修改
    edit_last_task_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(5) > td:nth-child(10) > a:nth-child(2)')
    # 编辑任务成功提示语
    edit_success_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    # 定位删除
    del_task_locator=(By.ID,'delete')
    # 定位删除成功的提示语
    del_task_success_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    # 定位不选择任务，直接点击删除的提示语
    del_task_unselect_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-error')
    # 定位最近分配任务
    recent_assign_locator = (By.LINK_TEXT, '最近分配')
    # 定位搜索输入框
    task_search_input_locator = (By.ID, 'search')
    # 定位搜索按钮
    task_search_btn_locator = (By.CSS_SELECTOR, '#dosearch')
    # 定位关闭
    close_task_locator = (By.LINK_TEXT, '关闭')
    # 定位关闭成功的提示语
    close_success_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    # 定位搜索失败的提示语
    search_default_locator=(By.CSS_SELECTOR,'#form1 > table > tbody > tr > td')
    # 定位搜索成功的提示语
    search_success_locator=(By.CSS_SELECTOR,'#form1 > table > tfoot > tr > td > div.pagination > div:nth-child(1)')

    # 点击新建任务
    def click_add_task(self):
        self.driver.find_element(*self.add_task_btn_locator).click()

    # 点击第一条任务
    def click_first_task(self):
        self.driver.find_element(*self.first_task_locator).click()

    # 点击最后一条任务
    def click_last_task(self):
        self.driver.find_element(*self.last_task_locator).click()

    # 点击最后一条任务的查看
    def look_last_task(self):
        self.driver.find_element(*self.look_last_task_locator).click()

    # 点击最后一条任务的修改
    def edit_last_task(self):
        self.driver.find_element(*self.edit_last_task_locator).click()

    # 点击删除
    def click_task_del(self):
        self.driver.find_element(*self.del_task_locator).click()

    # 点击最近分配的任务
    def click_recent_assign(self):
        self.driver.find_element(*self.recent_assign_locator).click()

    # 在搜索框输入存在的任务
    def input_exist_task(self,task):
        self.driver.find_element(*self.task_search_input_locator).send_keys(task)

    # 点击搜索按钮
    def click_search_btn(self):
        self.driver.find_element(*self.task_search_btn_locator).click()

    # 点击关闭
    def close_task(self):
        self.driver.find_element(*self.close_task_locator).click()

    # 获取任务页面的url地址
    def get_task_url(self):
        return self.current_url()

    # 获取任务编辑成功提示语
    def edit_task_success_tips(self):
        tips=self.driver.find_element(*self.edit_success_tips_locator).text
        return tips

    # 获取任务删除成功提示语
    def del_task_success_tip(self):
        tip=self.driver.find_element(*self.del_task_success_tips_locator).text
        return tip

    # 获取不选择任务，直接删除的提示语
    def del_task_unselect_tips(self):
        err_tip=self.driver.find_element(*self.del_task_unselect_tips_locator).text
        return err_tip
    def get_close_success_tips(self):
        '''获取关闭成功的提示语'''
        return self.driver.find_element(*self.close_success_tips_locator).text

    def get_search_default_tips(self):
        return self.driver.find_element(*self.search_default_locator).text

    def get_search_search_success_tips(self):
        return self.driver.find_element(*self.search_success_locator).text
